package com.jvyou.framework.controller;



import cn.dev33.satoken.annotation.SaIgnore;
import com.jvyou.common.annotation.Log;
import com.jvyou.common.core.domain.model.PageResult;
import com.jvyou.common.core.domain.model.Result;
import com.jvyou.common.enums.log.BusinessType;
import com.jvyou.common.enums.result.HttpCodeEnum;
import com.jvyou.framework.domain.dto.OperLogDto;
import com.jvyou.framework.domain.entity.OperLog;
import com.jvyou.framework.service.OperLogService;
import org.springframework.web.bind.annotation.*;
import lombok.RequiredArgsConstructor;
import cn.dev33.satoken.annotation.SaCheckPermission;
import java.util.List;

/**
 * 操作日志记录(OperLog)表控制层
 *
 * @author 橘柚
 * @since 2025-05-29 14:41:24
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/operLog")
public class OperLogController  {
    
    private final OperLogService operLogService;
    
     /**
     * 查询操作日志记录列表
     *
     * @param dto 查询参数
     * @return 操作日志记录
     */
    @GetMapping("/list")
    @SaIgnore
    @Log(title = "查询操作日志记录列表", businessType = BusinessType.OTHER)
    public Result<List<OperLog>> list(@ModelAttribute OperLogDto dto) {
        return Result.success(operLogService.listOperLog(dto));
    }

     /**
     * 分页查询操作日志记录列表
     *
     * @param dto 查询参数
     * @return 操作日志记录
     */
    @GetMapping("/page")
    @SaCheckPermission("sys:operLog:page")
    @Log(title = "分页查询操作日志记录列表", businessType = BusinessType.OTHER)
    public Result<PageResult<OperLog>> page(@ModelAttribute OperLogDto dto) {
        return Result.success(operLogService.pageOperLog(dto));
    }

    /**
     * 通过主键查询操作日志记录单条
     *
     * @param id 操作日志记录主键
     * @return 操作日志记录
     */
    @GetMapping("/{id}")
    @Log(title = "通过主键查询操作日志记录")
    @SaCheckPermission("sys:operLog:get")
    public Result<OperLog> selectOne(@PathVariable Long id) {
        return Result.success(operLogService.getById(id));
    }

    /**
     * 新增操作日志记录
     *
     * @param operLog 操作日志记录实体对象
     * @return 新增操作日志记录结果
     */
    @PostMapping
    @Log(title = "新增操作日志记录",  businessType = BusinessType.INSERT)
    @SaCheckPermission("sys:operLog:insert")
    public Result<OperLog> insert(@RequestBody OperLog operLog) {
        boolean success = operLogService.save(operLog);
        return success ? Result.success(operLog) : Result.error(HttpCodeEnum.ADD_FAIL);
    }
    
     /**
     * 修改操作日志记录
     *
     * @param operLog 操作日志记录实体对象
     * @return 修改操作日志记录结果
     */
    @PutMapping("/updateById")
    @SaCheckPermission("sys:operLog:update")
    @Log(title = "修改操作日志记录数据", businessType = BusinessType.UPDATE)
    public Result<OperLog> updateById(@RequestBody OperLog operLog) {
        boolean success = operLogService.updateById(operLog);
        return success ? Result.success(operLog) : Result.error(HttpCodeEnum.UPDATE_FAIL);
    }
    

    /**
     * 删除操作日志记录数据
     *
     * @param id 操作日志记录主键
     * @return 删除操作日志记录结果
     */
    @DeleteMapping("/{id}")
    @SaCheckPermission("sys:operLog:delete")
    @Log(title = "删除操作日志记录",  businessType = BusinessType.DELETE)
    public Result<Boolean> delete(@PathVariable Long id) {
        boolean success = operLogService.removeById(id);
        return success ? Result.success(true) : Result.error(HttpCodeEnum.DELETE_FAIL);
    }
    
}

